#include<iostream>
#include<math.h>
using std::endl;
using std::cout;
using std::string;
class Monster;
class Hero{
public:
    Hero(double hp,double hitNum,string name)
    :_hp(hp)
    ,_hitNum(hitNum)
    ,_name(name)
    {}
    //攻击方式
    void attack(Monster*monster)const;
public:
    //定义一个函数指针
    //typedef void (*function)();
    double _hp;
    double _hitNum; //伤害值
    string _name;
};

class Monster{
public:
    //攻击方式
    virtual void attack(Hero&hero)const = 0;
protected:
    Monster(double hp,double hitNum,string name)
    :_hp(hp)
    ,_hitNum(hitNum)
    ,_name(name)
    {}
public:
    //定义一个函数指针
    //typedef void (*function)();
    double _hp;
    double _hitNum; //伤害值
    string _name;
};
//写在后面可以解决 invalid use of incomplete type ‘class Monster’ 这个问题
void Hero::attack(Monster*monster)const{
        cout<<"Hero 准备攻击!"<<monster->_name.c_str();
        cout<<"Hero 打出了 "<<_hitNum<<" 伤害！"<<endl;
        monster->_hp-=_hitNum;
        cout<<monster->_name.c_str()<<" 还剩下 "<<monster->_hp<<" 的血量"<<endl;
}
class Goblin
:public Monster{
public:
    Goblin(double hp,double hitNum,string name,int id)
    :Monster(hp,hitNum,name)
    ,MonsterId(id)
    {
        cout<<"Goblin(double hp,double hitNum,string name,int id)"<<endl;
    }
public:
    virtual void attack(Hero&hero)const override{
        cout<<"Goblin 准备攻击!"<<hero._name.c_str();
        cout<<"Goblin 打出了 "<<_hitNum<<" 伤害！"<<endl;
        hero._hp = hero._hp - _hitNum;
        cout<<hero._name.c_str()<<" 还剩下 "<<hero._hp<<" 的血量"<<endl;
    }
public:
    int MonsterId;
};
#if 0
class Slime
:public Monster{

};
class Orcish
:public Monster{

};
#endif

int main(void){
    Hero hero(100,20,"hero");
    Goblin gol(50,10,"GOBLIN",1);
    gol.attack(hero);
    hero.attack(&gol);
    Monster *monster = &gol;
}